package team.sun.sss.controller.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.sun.sss.dao.log.BreakRuleDao;
import team.sun.sss.dao.log.NotifyDao;
import team.sun.sss.dao.staff.StaffDao;
import team.sun.sss.dao.student.StudentDao;

import java.util.List;
import java.util.Map;

@RestController
public class BreakRuleController {


    @Autowired
    BreakRuleDao breakRuleDao;

    @Autowired
    StudentDao studentDao;

    @Autowired
    NotifyDao notifyDao;

    @Autowired
    StaffDao staffDao;

    @GetMapping("/BreakRuleList")
    public List<Map<String,Object>> BreakRuleList(){
        List<Map<String,Object>> BreakRuleList=breakRuleDao.getBreakRuleList();
        return BreakRuleList;
    }

    @GetMapping("Break_delete/{id}")
    public String Break_delete(@PathVariable Integer id){
        try {
            breakRuleDao.Break_delete(id);
        }catch (Exception e){
            System.out.println(e);
            return "删除失败";
        }
        System.out.println("删除成功");
        return "删除成功";
    }


    @PostMapping("select_stu")
    public List<Map<String,Object>> getStuBreakList1( @RequestParam String stu_name, @RequestParam String stu_college, @RequestParam String stu_major){
        if(stu_name == "" ){
            stu_name =null;
        }
        if(stu_college == "" ){
            stu_college =null;
        }
        if(stu_major == "" ){
            stu_major =null;
        }
        System.out.println(stu_name+""+stu_college+stu_major);
        List<Map<String,Object>> StuBreakList=breakRuleDao.getStuBreakList1(stu_name,stu_college,stu_major);
        return StuBreakList;
    }

    @GetMapping("Break_Up/{bre_id}")
    public String Break_Up(@PathVariable int bre_id){
        try {
            breakRuleDao.Break_Up(bre_id);
            List<Map<String,Object>> b = breakRuleDao.getBreakRuleListOfBreId(bre_id);
            Map bre = b.get(0);
            List<Map<String ,Object>> s = studentDao.getUserList((Integer) bre.get("stu_id"));
            Map stu = s.get(0);
            try{
                notifyDao.addStuNotify((Integer) bre.get("stu_id"),"解除违纪处分公告","因为处分期满，给予解除违纪处分处理！","学工处");
                notifyDao.addIntNotify(staffDao.getStaIdOfName(stu.get("stu_instructor").toString()),"解除违纪处分公告",stu.get("stu_grade").toString()+"级"+stu.get("stu_college")+stu.get("stu_major")+stu.get("stu_class")+stu.get("stu_name")+"因为处分到期给予解除违纪处分处理！","学工处");
            }catch (Exception e){
                System.out.println(e);
            }
        }catch (Exception e){
            System.out.println(e);
            return "操作失败";
        }
        System.out.println("操作成功");
        return "操作成功";
    }
}
